1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import getRates from "$lib/rates";
import { auth, fd, post } from "$lib/utils";
import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, params, parent }) {
const { user } = await parent();
if (params.payreq.startsWith("lno")) return params;
const rates = await getRates();
const data = await post("/parse", params, auth(cookies));
data.rate = rates[user.currency];
data.payreq = params.payreq;
return data;
}
export const actions = {
setAmount: async ({ cookies, params, request }) => {
let data = await fd(request);
const { payreq } = params;
const { amount } = data;
if (payreq.startsWith("lno")) {
const { invoice } = await post("/fetchinvoice", {
amount,
offer: payreq,
});
data = await post("/parse", { payreq: invoice }, auth(cookies));
data.payreq = invoice;
}
return data;
},
send: async ({ cookies, request }) => {
let p;
try {
const body = await fd(request);
p = await post("/payments", body, auth(cookies));
} catch (_) {
return fail(400, { message: "payments.failedToRoute" });
}
redirect(307, `/sent/${p.id}`);
},
};
|